﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ggprot;

namespace GGTest
{
    public partial class Log : Form
    {
        private GaduProtocol protocol;

        public Log(GaduProtocol prot)
        {
            InitializeComponent();

            protocol = prot;
            prot.PacketReceived += new PacketEventHandler(prot_PacketReceived);
        }

        void prot_PacketReceived(object sender, PacketEventArgs e)
        {
            listBox1.Invoke(new Action(delegate()
                {
                    listBox1.Items.Add(string.Format("Received packet: {0} ({2}); Length: {1}", e.Packet.Type, e.Packet.Length, Enum.GetName(typeof(Packets), e.Packet.Type)));
                }));
        }

        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);

            protocol.PacketReceived -= prot_PacketReceived;
        }

        public void AppendLog(string log)
        {
            listBox1.Invoke(new Action(delegate()
                {
                    listBox1.Items.Add(log);
                }));
        }
    }
}
